package com.example.common;

import lombok.Data;

import java.io.Serializable;

/**
 * 用用返回类
 *
 * @author: 临晖
 * @since: 2024-04-01
 */
@Data
public class Result<T> implements Serializable {

    private Integer code; //编码：1成功，0和其它数字为失败
    private String msg; //错误信息
    private T data; //数据

    public static <T> Result<T> success() {     //成功，但是没有数据
        Result<T> result = new Result<T>();
        result.code = 1;
        return result;
    }

    public static <T> Result<T> success(T object) {     //成功，有数据
        Result<T> result = new Result<T>();
        result.data = object;
        result.code = 1;
        return result;
    }

    public static <T> Result<T> error(String msg) {     //失败，返回失败信息
        Result result = new Result();
        result.msg = msg;
        result.code = 0;
        return result;
    }


    public static <T> Result<T> error(String msg, Integer code) {     //失败，返回失败信息
        Result result = new Result();
        result.msg = msg;
        result.code = code;
        return result;
    }



}